import javax.sound.midi.*;
import java.io.*;

public class MidiPlayer implements Runnable {

    public static void main(String args[]) {        }
    
    public MidiPlayer() {}
    
    public void run() {
   
    
    
    
 

        java.net.URL midiURL = GraphicsHelper.getURL("Material/rammsteinhintergrund.mid");


        try {
            Sequencer sequencer = MidiSystem.getSequencer();
            sequencer.setSequence(MidiSystem.getSequence(midiURL));
            sequencer.open();
            sequencer.start();
            while(true) {
                if(sequencer.isRunning()) {
                    try {
                        Thread.sleep(1000);
                    } catch(InterruptedException ignore) {
                        break;
                    }
                } else {
                    break;
                }
            }            
            sequencer.stop();
            sequencer.close();
        }
        catch(MidiUnavailableException e) {
            System.out.println("Midi device unavailable!");
            e.printStackTrace();
        } 
        catch(InvalidMidiDataException e) {
            System.out.println("Invalid Midi data!");
            e.printStackTrace();
        } 
        catch(IOException e) {
            System.out.println("I/O Error!");
            e.printStackTrace();
        } 

    }  
}